// 路由配置
import Layout from '@/pages/Layout'
import Login from '@/pages/Login'
import AuthRoute from '@/components/AuthRoute/index'

import { createBrowserRouter } from 'react-router-dom'
// import Home from '@/pages/Home'
// import Publish from '@/pages/Publish'
// import Article from '@/pages/Article'
import { lazy, Suspense } from 'react'

// 1. lazy函数对组件进行导入
const Home = lazy(() => import('@/pages/Home'))
const Publish = lazy(() => import('@/pages/Publish'))
const Article = lazy(() => import('@/pages/Article'))

// 配置路由实例
const router = createBrowserRouter([
  {
    path: '/',
    element: <AuthRoute><Layout /></AuthRoute>,
    children: [
      {
        path: '/',
        element: <Suspense fallback={'加载中'}><Home /></Suspense>
      },
      {
        path: '/publish',
        element: <Suspense fallback={'加载中'}><Publish /></Suspense>
      },
      {
        path: '/article',
        element: <Suspense fallback={'加载中'}><Article /></Suspense>
      }
    ]
  },
  {
    path: '/login',
    element: <Login />
  }
])

export default router

